/**
 * @author rxliuli
 */
const {
    wait,
    arrayToMap,
} = rx
const app = new BaseValidateVue({
    el: '#app',
    data() {
        return {
            form: new BaseOperCompany(),
            officerMap: new Map(),
            ruleList: [
                new ValidateObject({
                    ruleName: 'idcId_validate',
                    validate: this.idcIdValidate,
                }),
            ],

        }
    },
    methods: {
        createValidateList() {
            return this.ruleList;
        },
        /**
         * 新增经营单位信息
         */
        async add() {
            this.$validator.validateAll().then(async (res) => {
                if (res) {
                    if (await ajaxOption({
                        res: baseOperCompanyApi.add({
                            ...this.form,
                            updateTime: new Date().toISOString(),
                        }),
                        danger: '新增失败',
                        success: '新增成功，即将返回列表页面',
                    })) {
                        await wait(1000)
                        forward('/basic-data/admin_idc_info')
                    }
                } else {
                    rxPrompt.dangerMsg("输入存在错误！");
                }
            })
        },
        async idcIdValidate(val, args) {
            const {idcId = ''} = this.form;
            if (idcId === '' || val === '') {
                return true;
            }
            const result = await baseOperCompanyApi.existsById(val)
            return !result;
        },
    },
    computed: {},
    async mounted() {
        this.officerMap = arrayToMap(await baseHouseOfficerApi.selectList(), ({id}) => id, ({name}) => name)
    },
})
